using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FanDongping.Stock
{
    public partial class FmBrowse : Form
    {

        public FmBrowse()
        {
            InitializeComponent();
        }

        private void fmBrowse_Load(object sender, EventArgs e)
        {

            bindHistory.DataSource = StockData.TradeHistory.Trades;

            Color c = Color.BlueViolet;
            foreach (DataGridViewRow gr in grdTrades.Rows)
            {
                if (((TradeType)gr.Cells["tradeTypeDataGridViewTextBoxColumn"].Value) == TradeType.BUY)
                {
                    c = Color.Red;
                }

                foreach (DataGridViewCell gc in gr.Cells)
                {
                    gc.Style.ForeColor = c;
                    gc.Style.BackColor = c;
                }
            }

        }

        private void tradeHistoryBindingSource_CurrentChanged(object sender, EventArgs e)
        {

        }

        private void grdTrades_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            bindHistory.ResetBindings(true);
        }

        private void grdTrades_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            e.ThrowException = true;
        }

        private void grdTrades_DoubleClick(object sender, EventArgs e)
        {
            Trade t = bindHistory.Current as Trade;
            FmMain fmain = this.MdiParent as FmMain;
            fmain.CloseMdiForm(typeof( FmEditTrade));
            FmEditTrade editTrade = new FmEditTrade(t);
            editTrade.MdiParent = fmain;
            editTrade.Show();

        }
    }
}